<include file="Public/header"/>
<body class="body-bg">
<div class="park-header">
    <form class="park-search-group">
        <div class="park-search-input">
            <input type="text" id="keywords" value="{$keywords}" placeholder="请输入商品名进行搜索">
        </div>
        <div class="park-search-cancel" onclick="get_search();">搜索</div>
    </form>
</div>
<div class="park-sortNav-tabs">
    <ul id="nav_type">
        <li data-id="1" <if condition="$type_id eq 1">class="active"</if>>默认</li>
        <li data-id="2" <if condition="$type_id eq 2">class="active"</if>>最新</li>
        <li data-id="3" <if condition="$type_id eq 3">class="active"</if>>销量</li>
        <li data-id="4" data-type="{$desc}" class="price <if condition='$type_id eq 4'>active</if>">
            价格
            <span>
                <i class="iconfont icon-shangjiantou"></i>
                <i class="iconfont icon-xiajiantou"></i>
            </span>
        </li>
    </ul>
</div>
<div class="container">
    <div class="park__goods">
        <ul id="goods_list"></ul>
    </div>
</div>
<div class="park-fixed-cart" onclick="window.location='/Home/Cart/index/';">
    <i class="iconfont icon-cart"></i>
    <span class="num" id="cart_number" <if condition="$cart_number lt 1">style="display:none;"</if>>{$cart_number}</span>
</div>
</body>
<script src="__ROOT__/Public/Home/layer/layer.js"></script>
<script>
    function goods_detail(id,store_id){
        window.location = "{:U('Home/Index/detail',"",false)}/id/"+id+'/store_id/'+store_id;
    }
    var options = {
        type: 'get', // default 'get'
        dataType: 'html' // default 'json'
    };
    $(function () {
        var url = '/Home/Index/goods_list/';
        var keywords = '{$keywords}';
        var type_id = '{$type_id}';
        var desc = '{$desc}';
        var params = {'keywords':keywords,'act':'ajax','type_id':type_id,'desc':desc};
        PARK.dropLoad(PARK.dropAjax(options, url, params, function (data) {
            var data = JSON.parse(data);
            var html = '';
            for (var i = 0; i < data.result.length; i++) {
                var saleout = '';
				html += '<li>';
				if(data['result'][i]['is_sold']==1){
					saleout = 'saleout';
				}
                html += '    <div onclick="goods_detail(' + data['result'][i]['id'] + ',' + data['result'][i]['store_id'] + ');" class="park-goods__pic '+saleout+'" style="background-image: url(' + data['result'][i]['thumb'] + ')"></div>';
                html += '    <div onclick="goods_detail(' + data['result'][i]['id'] + ',' + data['result'][i]['store_id'] + ');" class="park-goods__info">';
                html += '        <p class="name">' + data['result'][i]['goods_name'] + '</p>';
                html += '        <p class="desc">' + data['result'][i]['store_name'] + '</p>';
                html += '        <p class="spec">' + data['result'][i]['spec_name'] + '&nbsp;</p>';
                html += '        <p class="price-line">';
                html += '            <span class="price">￥<em>' + data['result'][i]['left_price'] + '</em>' + data['result'][i]['right_price'] + '</span>';
                html += '        </p>';
                html += '    </div>';
                html += '    <div class="park-goods__pos">';
                html += '        <div class="cart" onclick="sum_form('+data['result'][i]['goods_id']+','+data['result'][i]['store_id']+','+data['result'][i]['spec_id']+');">';
                html += '            <i class="iconfont icon-cart"></i>';
                html += '        </div>';
                html += '    </div>';
                html += '</li>';
            }
            $('#goods_list').append(html);
            if(data.is_page==1){
                PARK.unDropLoad();
            }
        }));
        $(document).on('click', '#nav_type li', function () {
            $(this).addClass('active').siblings().removeClass('active');
            var id = $(this).attr('data-id');
            if(id==4){
                var desc = $(this).attr('data-type');
                if(desc=='asc'){
                    desc = 'desc';
                }else{
                    desc = 'asc';
                }
                var url = '/Home/Index/goods_list/type_id/'+id+'/keywords/'+keywords+'/desc/'+desc;
            }else{
                var url = '/Home/Index/goods_list/type_id/'+id+'/keywords/'+keywords;
            }
            window.location = url;
        });
    });
    function get_search(){
        var name = $('#keywords').val();
        window.location = '/Home/Index/goods_list/keywords/'+name;
    }
	function sum_form(goods_id,store_id,spec_id){
        if(!spec_id){
            return false;
        }
        var goods_number = 1;
        $.post('/Home/Cart/add_cart/',{goods_id:goods_id,store_id:store_id,spec_id:spec_id,goods_number:goods_number},function(data){
            if(data.code==200){
                $('#cart_number').show().html(data.result);
            }
            layer.open({
                content:data.msg
                ,skin: 'msg'
                ,time: 2 //2秒后自动关闭
            });
        },'json');
    }
</script>
</html>